/**
 * 
 */

package com.pp.admin.main.client.tab.objectpages;

import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.pp.admin.common.client.beans.User;
import com.pp.admin.common.client.helper.AdminFlexTable;
import com.pp.admin.common.client.helper.AdminFormTextBox;

/**
 * @author pandurang
 */
public class UserInfo extends AdminFlexTable {

	private User user = null;

	private AdminFormTextBox userID = new AdminFormTextBox();

	private AdminFormTextBox firstName = new AdminFormTextBox();

	private AdminFormTextBox lastName = new AdminFormTextBox();

	private PasswordTextBox password = new PasswordTextBox();

	static final int USER_INFO_LBL_ROW = 0;

	static final int USER_ID_ROW = 1;

	static final int FIRST_NAME_ROW = 2;

	static final int LAST_NAME_ROW = 3;

	static final int PASSWORD_ROW = 4;

	static final int NO_TABLE_COLS = 2;

	public UserInfo(User userBean) {
		user = userBean;
		init();
		userID.setText(userBean.getUserID());
		userID.setEnabled(false);
		firstName.setText(userBean.getFirstName());
		lastName.setText(userBean.getLastName());
		password.setText(userBean.getPassword());
	}

	public UserInfo() {
		user = new User();
		init();
	}

	public void init() {
		this.setWidget(USER_INFO_LBL_ROW, LABEL_COL, new Label(myConstants
				.userinfo()
				+ " : "));
		this.setTdAttribute(USER_INFO_LBL_ROW, LABEL_COL,
				AdminFlexTable.ATR_TD_COLSPAN, "" + NO_TABLE_COLS);
		this.setWidget(USER_ID_ROW, LABEL_COL, new Label(myConstants.username()
				+ " : "));
		this.getCellFormatter().setHorizontalAlignment(USER_ID_ROW, LABEL_COL,
				HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(USER_ID_ROW, FIELD_COL, userID);
		this.setWidget(FIRST_NAME_ROW, LABEL_COL, new Label(myConstants
				.firstName()
				+ " : "));
		this.getCellFormatter().setHorizontalAlignment(FIRST_NAME_ROW,
				LABEL_COL, HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(FIRST_NAME_ROW, FIELD_COL, firstName);
		this.setWidget(LAST_NAME_ROW, LABEL_COL, new Label(myConstants
				.lastName()
				+ " : "));
		this.getCellFormatter().setHorizontalAlignment(LAST_NAME_ROW,
				LABEL_COL, HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(LAST_NAME_ROW, FIELD_COL, lastName);
		this.setWidget(PASSWORD_ROW, LABEL_COL, new Label(myConstants.pwd()
				+ " : "));
		this.getCellFormatter().setHorizontalAlignment(PASSWORD_ROW, LABEL_COL,
				HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(PASSWORD_ROW, FIELD_COL, password);

	}

	public User getUser() {

		user.setUserID(userID.getTextBox().getText());
		user.setFirstName(firstName.getTextBox().getText());
		user.setLastName(lastName.getTextBox().getText());
		user.setPassword(password.getText());
		return user;
	}

}
